package com.wangwenshuo.goods.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wangwenshuo.goods.dao.GoodsMapper;
import com.wangwenshuo.goods.entity.Goods;
import com.wangwenshuo.goods.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsServiceImpl implements GoodsService {
    @Autowired
    private GoodsMapper goodsMapper;
    @Override
    public PageInfo<Goods> selectGoods(Goods goods, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Goods> list = goodsMapper.selects(goods);
        return new PageInfo<>(list);
    }

    @Override
    public boolean del(String ids) {
        return goodsMapper.del(ids)>0;
    }

    @Override
    public Goods getById(Integer id) {
        return goodsMapper.getById(id);
    }

    @Override
    public boolean save(Goods goods) {
        if(goods.getId()==null){
            return goodsMapper.insert(goods)>0;
        }
        return goodsMapper.update(goods)>0;
    }
}
